﻿using PSI.Helper;
using PSI.Models.TMS;
using PSI.Services;
using PSI.Services.TMS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace PSI.Controllers {
    public class TruckController : PSIController {
        public ActionResult Index() {
            var ps = new PermissionService();
            if (!ps.HasPermission(FIdConst.TRUCK_MANAGEMENT)) {
                return Redirect("/");
            }

            ViewBag.UserName = UserService.GetLoginUserName();
            ViewBag.CloseFlag = Request.Params["CloseFlag"];
            return View();
        }

        [HttpPost]
        public ActionResult GetTruckCompanyList() {
            var data = new TruckService().GetTruckCompanyList();

            return Json(data);
        }

        [HttpPost]
        public ActionResult GetTruckList(string id) {
            var data = new TruckService().GetTruckList(id);

            return Json(data);
        }

        [HttpPost]
        public ActionResult EditTruckCompany(TruckCompany truck) {
            if (string.IsNullOrEmpty(truck.Id))
            {
                truck.password = "123456";
            }            
            var result = new TruckService().EditTruckCompnay(truck);
            return Json(result);
        }

        [HttpPost]
        public ActionResult EditTruck(Truck truck) {
            var result = new TruckService().EditTruck(truck);

            return Json(result);
        }

        [HttpPost]
        public ActionResult QueryTruckCompany(string queryKey) {
            var data = new TruckService().QueryTruckCompany(queryKey);

            return Json(data);
        }

        [HttpPost]
        public ActionResult QueryTruckNumber(string truckCompany, string queryKey) {
            var data = new TruckService().QueryTruckNumber(truckCompany, queryKey);

            return Json(data);
        }
        [HttpPost]
        public ActionResult ResetPWD(string truckid)
        {
            var bol = new TruckService().ReserPassWord(truckid);
            if (bol)
                return Json("");
            else
                return Json("网络原因操作失败");          
            
        }

        [HttpPost]
        public ActionResult DisablePWD(string truckid,string flag)
        {
            var bol = new TruckService().DisablePassWord(truckid,flag);
            if (bol)
                return Json("");
            else
                return Json("网络原因操作失败");

        }
    }
}
